#include <stdio.h>
#include <unistd.h>
#include <sys/eventfd.h>

int main()
{
    /* eventfd - create a file descriptor for event notification */
    int init = 0;//eventfd计数器的初始值
    int efd = eventfd(init, EFD_CLOEXEC | EFD_NONBLOCK);//对efd的操作都是非阻塞的
    if (efd < 0)
    {
        perror("eventfd failed!!");
        return -1;
    }
    uint64_t val = 1;//必须是8字节的数据
    write(efd, &val, sizeof val); 
    write(efd, &val, sizeof val); 
    write(efd, &val, sizeof val); 
    uint64_t res = 0;
    read(efd, &res, sizeof res);

    printf("res: %ld\n", res);
    close(efd);
    return 0;
}